{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8acdf291-9ca6-475e-aa00-77fc2a522cc3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[ 2.8585,  4.1258, -1.6463, -0.0817],\n",
       "        [ 0.8593,  0.7854, -0.3882, -0.8267],\n",
       "        [ 1.0413,  0.3772, -0.4258,  0.6339]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "from d2l import torch as d2l\n",
    "X,W_xh = torch.normal(0,1,(3,1)),torch.normal(0,1,(1,4))\n",
    "H,W_hh = torch.normal(0,1,(3,4)),torch.normal(0,1,(4,4))\n",
    "torch.matmul(X,W_xh) + torch.matmul(H,W_hh)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5b100b40-9fcc-4fdd-90b0-539b501a997e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[ 2.8585,  4.1258, -1.6463, -0.0817],\n",
       "        [ 0.8593,  0.7854, -0.3882, -0.8267],\n",
       "        [ 1.0413,  0.3772, -0.4258,  0.6339]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "torch.matmul(torch.cat((X,H),1),torch.cat((W_xh,W_hh),0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "829b081f-9b18-4859-951e-949f644bcee3",
   "metadata": {},
   "outputs": [],
   "source": [
    "#8.4.3. 基于循环神经网络的字符级语言模型"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
